﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace 文件夹清理工具
{
    class Viewer
    {
        internal static void DrawForm(Form me)
        {
            double width = me.DisplayRectangle.Width;
            double height = me.DisplayRectangle.Height;
            Control 数据表, 清理;
            数据表 = new Control();
            清理 = new Control();
            foreach (Control _ctrl in me.Controls)
            {
                switch (_ctrl.Name)
                {
                    case "数据表":
                        数据表 = _ctrl;
                        break;
                    case "清理":
                        清理 = _ctrl;
                        break;
                }
            }
            数据表.Height = (int)(height - 清理.Height - 15);
            数据表.Width = (int)(width -  10);
            数据表.Top = 5;
            数据表.Left = 5;

            清理.Top = 数据表.Height + 10;
            清理.Left = (int)(width - 清理.Width - 5);

        }

        internal static void DrawDataGrid(DataGridView 数据表)
        {
            List<double> colwidth = new List<double>();
            double SumUp = 0;
            for (int j = 0; j < 数据表.Columns.Count; j++)
            {
                double Max = 0;
                for (int i = 0; i < 数据表.Rows.Count; i++)
                {
                    if (数据表.Font == null) continue;
                    if (数据表.Font.FontFamily == null) continue;
                    if (数据表.Font.FontFamily.Name == null) continue;
                    if (数据表.Rows[i].Cells[j].Value == null) continue;
                    double w = YZZ.Tools.MeasureTextWidth(数据表.Rows[i].Cells[j].Value.ToString(), 数据表.Font.Size, 数据表.Font.FontFamily.Name);
                    if (w > Max)
                        Max = w;
                }
                colwidth.Add(Max * 1.5);
                SumUp += Max * 1.5;
            }
            for (int i = 0; i < colwidth.Count; i++)
            {
                double colw = (((double)数据表.Width) / SumUp * colwidth[i]);
                数据表.Columns[i].Width = (int)(colwidth[i] > colw ? colwidth[i] : colw);
            }
        }
    }
}
